package com.cs157a.view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;

import com.cs157a.controller.AposApplicationController;
import com.cs157a.dao.Make;
import com.cs157a.dao.RdiPart;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 * This class shows the dialog for input new auto.
 * 
 * @author hhong
 * 
 */
public class PartListDialog extends JDialog {

	private static final long serialVersionUID = 20012100301L;
	private AposApplicationController controller;
	private PartListPanel partListPanel;
	private JButton selectButton;
	private JButton cancelButton;

	public PartListDialog(final AposApplicationController controller) {
		super();
		this.controller = controller;

		setPreferredSize(new Dimension(800, 400));

		selectButton = new JButton(CommonString.SELECT);
		selectButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
			}
		});
		cancelButton = new JButton(CommonString.CANCEL);
		cancelButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				setVisible(false);
			}
		});

		JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
		buttonPanel.add(selectButton);
		buttonPanel.add(cancelButton);

		List<RdiPart> parts = controller.getAllParts();
		partListPanel = new PartListPanel(parts);

		add(partListPanel, BorderLayout.CENTER);
		add(buttonPanel, BorderLayout.SOUTH);
		setModalityType(ModalityType.APPLICATION_MODAL);

	}

	public List<RdiPart> getSelectedPart() {
		return partListPanel.getSelectedPart();
	}

}
